import BaseRole from "battle/components/role/BaseRole";
import Map from "battle/components/Map";
import { SharkBullet } from "battle/components/role/Bullet";

/**
 * 鲨鱼
 */

 export default class Shark extends BaseRole {

 	constructor(data) {
        super(data);
        this.ho = 2;
    }
    
    /**
     * 攻击指示器
     */
    updateSightLine(direct) {
        let range = 80;
        let graphics = this.indicator.graphics;
        graphics.clear();
        let angle = 180 * Math.atan2(direct[1], direct[0]) / Math.PI;
        graphics.drawPie(0, 0, 200, 0, range, "#ffffff");
        this.indicator.rotation = angle - range/2;
        this.indicator.alpha = 0.5;
        (direct[0]!==0) && (this.faceDirect = (direct[0]<0)? -1: 1);
    }

    attack(data) {
        let mapView = Map.getInstance();
        let count = 0;
        let _loop = ()=> {
            if (++count==5) Laya.timer.clear(this, _loop);
            let bullet = new SharkBullet();
            bullet.pos(this.x, this.y-60);
            mapView.addChild(bullet);
            bullet.flyTo(this.x+400, this.y-60);
        };
        Laya.timer.loop(50, this, _loop);
    }

 }